﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using QuadraticEquationPresenter;
using Infrastructure;

namespace QuadraticEquation
{
    public partial class WFAView : Form, IQuadraticEquationView
    {
        public event Action solveButtonPressed;
        public event Action showLogButtonPressed;
        public event Action<bool> loggerStateChangedToFileLogger;
        private IFactoryLogger factoryLogger;

        public WFAView()
        {
            InitializeComponent();
            factoryLogger = new FactoryLogger();
            Presenter presenter = new Presenter(this, factoryLogger);
        }

        private void buttonSolve_Click(object sender, EventArgs e)
        {
            solveButtonPressed();
        }

        public string aField
        {
            get
            {
                return textBoxA.Text;
            }
        }

        public string bField
        {
            get
            {
                return textBoxB.Text;
            }
        }
        public string cField
        {
            get
            {
                return textBoxC.Text;
            }
        }
        public string x1Field
        {
            set
            {
                textBoxX1.Text = value;
            }
        }
        public string x2Field
        {
            set
            {
                textBoxX2.Text = value;
            }
        }
        public string messageAboutRootsField
        {
            set
            {
                messageAboutRoots.Text = value;
            }
        }
        public string errorMessageField
        {
            set
            {
                errorMessage.Text = value;
            }
        }
        public string logText
        {
            get
            {
                return logRichTextBox.Text;
            }
            set
            {
                logRichTextBox.Text = value;
            }
        }

        private void showLogButton_Click(object sender, EventArgs e)
        {
            showLogButtonPressed();
        }

        private void fileLoggerRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (sender is RadioButton)
            {
                RadioButton loggerButton = (RadioButton)sender;
                if (loggerButton.Checked) 
                {
                    loggerStateChangedToFileLogger(true);
                }
                else
                {
                    loggerStateChangedToFileLogger(false);
                }
            }
        }

    }
}
